import axios from '../utils/axios'
import { ref } from 'vue'

// const host = 'http://10.237.206.137:8092/'
export const getJiaDingAPIFindTypeAndDateNum = () => {
    let url = `JiaDingAPI/city-operation/beaconpage/findTypeAndDateNum`
    const dataitems = ref({})
    const tzcount = ref(0)
    axios
        .get(url)
        .then((res) => {
            res.data.data.map((item) => (item.value = Number(item.value)))
            dataitems.value = res.data.data
            for (let item of res.data.data) {
                tzcount.value += Number(item.value)
            }
        })
        .catch((error) => {})
    return { dataitems, tzcount }
}
export const getJiaDingAPIfindAllCaseMsg = () => {
    let url = `JiaDingAPI/city-operation/beaconpage/findAllCaseMsg`
    const fromsData = ref([])
    axios
        .get(url)
        .then((res) => {
            fromsData.value = res.data.data
        })
        .catch((error) => {})
    return fromsData
}
export const getJiaDingAPIfindChengshiMsg = () => {
    let url = `JiaDingAPI/city-operation/beaconpage/findChengshiMsg`
    const data = ref({})
    const ctcount = ref(0)
    axios
        .get(url)
        .then((res) => {
            let content = res.data.data
            content.map((item,index)=>{
                item.map(child=>{
                    console.log(child)
                    child.pop_type=child.datatype||''
                    child.id=child.title
                })
            })
            let newcontent = {
                chengshizhisheng: content[0],
                chengshizhigan: content[1],
                chengshizhiyan: content[2],
                chengshihuxi: content[3],
                chengshiwendu: content[4],
                chengshimaibo: content[5]
            }
            let oldctcount = 0
            data.value = newcontent
            for (let key in newcontent) {
                oldctcount += newcontent[key].length
            }
            ctcount.value = oldctcount
        })
        .catch((error) => {})
    return { data, ctcount }
}

// 城市之感(列表)
export const getSensor = async (id, pageIndex = 1, dataType = 1, address = '') => {
    console.log(pageIndex)
    let status = '安装'
    // if (pageIndex == null) {
    //     pageIndex = 1
    // }
    if (dataType == 1) {
        status = '安装'
    } else {
        status = '告警'
    }
    let url = `JiaDingAPI/city-operation/beaconpage/findListMsg?name=${id}&page=${pageIndex}&size=6&address=${address}&status=${status}`
    let list = 0
    const {data} = await axios.get(url)

    if (data.code == 0) {
        list = data.data
    }

    return list
}
interface data{
    title:string,
    list:any
}
// 城市之声(今日,本周)
export const getRegion = async (id) => {
    console.log(id,'id')
    let   url=`JiaDingAPI/city-operation/beaconpage/findListMsg?name=${id}`

    let list = []
    let newdata:data={
        title:id,
        list:[]
    }
    const { data } = await axios.get(url)

    if (data.code == 0) {


        newdata=data.data
       // data.data.map(item=>{
       //     // @ts-ignore
       //     newdata.list.push({
       //         address: item.address,
       //         dayNum: item.dayNum,
       //         dayUnit: item.unit || '',
       //         weekNum: item.weekNum,
       //         weekUnit: item.unit || '',
       //     })
       // })
    }
    return newdata
}

// 运行状态
export const getRunState = async () => {
    let url = `JiaDingAPI/city-operation/beaconpage/findGarbageIsAlarm`
    let state = 0
    const { data } = await axios.get(url)

    if (data.code == 0) {
        state = data.data.describe
    }

    return state
}


